package com.yookey.common.exception;

import com.yookey.common.constant.ResponseMessageEnum;
import lombok.Getter;
import lombok.Setter;
import org.springframework.http.HttpStatus;

/**
 * className ParamException
 *
 * @Author: Zhang Shao Hui
 * @Description:
 * @Date:Create：in 2019/8/20 10:56
 * @Modified By：
 */
@Getter
@Setter
public class ParamException extends RuntimeException {

    private static final long serialVersionUID = 6146006238867038595L;
    private String message;
    private String code;
    private Object[] params;
    private HttpStatus httpStatus;

    public Object[] getParams()
    {
        if (params == null)
        {
            return null;
        }
        return (Object[])params.clone();
    }

    public void setParams(Object[] params)
    {
        if (params == null)
        {
            this.params = null;
        } else {
            this.params = (Object[])params.clone();
        }
    }

    public ParamException(String code, String message) {
        this.code = code;
        this.message=message;
    }

    public ParamException(Object... params) {
        this.setParams(params);
    }

    public ParamException(ResponseMessageEnum responseMessageEnum) {
        this.code = responseMessageEnum.getMessageKey();
        this.setParams(null);
    }

    public ParamException(HttpStatus statusCode, ResponseMessageEnum responseMessageEnum) {
        this.code = responseMessageEnum.getMessageKey();
        this.setParams(null);
        setHttpStatus(statusCode);
    }

    public ParamException(ResponseMessageEnum responseMessageEnum, Object... params) {
        this.code = responseMessageEnum.getMessageKey();
        this.setParams(params);
    }

    public ParamException(HttpStatus statusCode, ResponseMessageEnum responseMessageEnum, Object... params) {
        this.code = responseMessageEnum.getMessageKey();
        this.setParams(params);
        setHttpStatus(statusCode);
    }

    public ParamException(String code, ResponseMessageEnum responseMessageEnum, Object... params) {
        this.code = responseMessageEnum.getMessageKey();
        this.setParams(params);
        this.code = code;
    }
}
